package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.cache.redis.service.IStrategyStatisVOService;
import cn.wolfcode.wolf2w.cache.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisDataPersistenceJob {
    @Autowired
    private IStrategyStatisVOService strategyStatisVOService;
    @Autowired
    private IStrategyService strategyService;

    @Scheduled(cron = "0/10 * * * * ?")
    public void doWork() {
        System.out.println("-----------持久化start----------------");
        // 查询redis中的所有vo对象
        // Pattern : 就是redis操作中的查询条件,
        // 比如说 keys STRATEGY_STATIS_VO : *   就是查询所有以 STRATEGY_STATIS_VO 开头的key
        List<StrategyStatisVO> vos = strategyStatisVOService.queryVoByPattern("*");
        // 把查询到的vo对象update 进mongodb中
        for (StrategyStatisVO vo : vos){
            strategyService.updateVo(vo);
        }
        System.out.println("-----------持久化end----------------");
    }
}
